<?php
namespace App\Model;

use App\Modules\Relationship\Interfaces\ModelInterface;
use App\Http\Services\CommonServices;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;
use App\Http\Model\Base;

class SweetFriend extends BaseModel
{

    protected $table = "rs_sweet_friend";
    protected $titleTable = "rs_sweet_user_title";
    protected $fields = ['id', 'user_id as userId', 'friend_id as friendId',
        'intimate', 'title_id as titleId',
        'level', 'created_time as createdTime'];
    protected $tablePrefix = '';

    public function __construct(array $attributes = [])
    {
        $this->tablePrefix = env('DB_PREFIX_API');
    }

    public function getList($userId, $friendId) {
        $param1 = array(
            'user_id'=>$userId,
            'friend_id'=>$friendId,
            'is_deleted'=>0
            );
        $rows1 = DB::connection($this->connection)
            ->table($this->table)
            ->where($param1)
            ->select($this->fields)
            ->get();
        $rows1 = $this->objToArray($rows1);
        $param2 = array(
            'user_id'=>$friendId,
            'friend_id'=>$userId,
            'is_deleted'=>0
        );
        $rows2 = DB::connection($this->connection)
            ->table($this->table)
            ->where($param2)
            ->select($this->fields)
            ->get();
        $rows2 = $this->objToArray($rows2);
        $rows1[0]['friendTitleId'] = $rows2[0]['titleId'];
        return $rows1[0];
    }
}
?>